define(['jquery', 'bootstrap', 'backend', 'form', 'table', 'tinymce'], function ($, undefined, Backend, Form, Table, tinymce) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'expert/position/index',
                    table: 'position'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'id',
                columns: [
                    [
                        { field: 'state', checkbox: true },
                        { field: 'id', title: "ID", searchable: false, search: false },
                        { field: 'user', title: "用户", searchable: false, formatter: Controller.api.formatter.user, },
                        { field: 'level_type', title: "身份类型", searchable: false, formatter: Controller.api.formatter.level_type, },
                        { field: 'limit_position_num', title: "点位限制", searchable: false, },
                        { field: 'user1', title: "占位1", searchable: false, formatter: Controller.api.formatter.user1, },
                        { field: 'user2', title: "占位2", searchable: false, formatter: Controller.api.formatter.user2, },
                        { field: 'user3', title: "占位3", searchable: false, formatter: Controller.api.formatter.user3, },
                        { field: 'user4', title: "占位4", searchable: false, formatter: Controller.api.formatter.user4, },
                        { field: 'user5', title: "占位5", searchable: false, formatter: Controller.api.formatter.user5, },
                        { field: 'user6', title: "占位6", searchable: false, formatter: Controller.api.formatter.user6, },
                        { field: 'user7', title: "占位7", searchable: false, formatter: Controller.api.formatter.user7, },
                        { field: 'user8', title: "占位8", searchable: false, formatter: Controller.api.formatter.user8, },

                    ]
                ],
                // commonSearch: false,
                visible: false,
                showToggle: false,
                showColumns: false,
                showExport: false,
                pageList: [10, 25, 50, 100, 'All']
            });

            //给添加按钮添加`data-area`属性
            $(".btn-add").data("area", ["80%", "100%"]);

            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".btn-editone,.btn-edit").data("area", ["80%", "100%"]);
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                thumb: function (value, row, index) {
                    var html = '';
                    if (value.indexOf("jpg") > -1 || value.indexOf("jpeg") > -1 || value.indexOf("png") > -1 || value.indexOf("gif") > -1) {
                        html = '<a href="' + row.cover + '" target="_blank"><img src="' + row.cover + '" alt="" style="max-height:60px;max-width:120px"></a>';
                    }
                    return '<div style="width:120px;margin:0 auto;text-align:center;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;">' + html + '</div>';
                },
                yes_or_no: function (value, row, index) {
                    var html = "";
                    if (value == "1") {
                        html = "是";
                    } else {
                        html = "否";
                    }
                    return html;
                },
                user: function (value, row, index) {
                    var html = row["nickname"] + "<br/>" + row["mobile"] + "<br>团队：【" + row["team_count"]+"】";
                    return html;
                },
                user1: function (value, row, index) {
                    var html = "";
                    if (row["mobile1"] != "") {
                        html = row["nickname1"] + "<br/>" + row["mobile1"] + "<br>团队：【" + row["team_count1"]+"】";
                    }
                    return html;
                },
                user2: function (value, row, index) {
                    var html = "";
                    if (row["mobile2"] != "") {
                        html = row["nickname2"] + "<br/>" + row["mobile2"] + "<br>团队：【" + row["team_count2"]+"】";
                    }
                    return html;
                },
                user3: function (value, row, index) {
                    var html = "";
                    if (row["mobile3"] != "") {
                        html = row["nickname3"] + "<br/>" + row["mobile3"] + "<br>团队：【" + row["team_count3"]+"】";
                    }
                    return html;
                },
                user4: function (value, row, index) {
                    var html = "";
                    if (row["mobile4"] != "") {
                        html = row["nickname4"] + "<br/>" + row["mobile4"] + "<br>团队：【" + row["team_count4"]+"】";
                    }
                    return html;
                },
                user5: function (value, row, index) {
                    var html = "";
                    if (row["mobile5"] != "") {
                        html = row["nickname5"] + "<br/>" + row["mobile5"] + "<br团队：【" + row["team_count5"]+"】";
                    }
                    return html;
                },
                user6: function (value, row, index) {
                    var html = "";
                    if (row["mobile6"] != "") {
                        html = row["nickname6"] + "<br/>" + row["mobile6"] + "<br>团队：【" + row["team_count6"]+"】";
                    }
                    return html;
                },
                user7: function (value, row, index) {
                    var html = "";
                    if (row["mobile7"] != "") {
                        html = row["nickname7"] + "<br/>" + row["mobile7"] + "<br>团队：【" + row["team_count7"]+"】";
                    }
                    return html;
                },
                user8: function (value, row, index) {
                    var html = "";
                    if (row["mobile8"] != "") {
                        html = row["nickname8"] + "<br/>" + row["mobile8"] + "<br>团队：【" + row["team_count8"]+"】";
                    }
                    return html;
                },
                level_type: function (value, row, index) {
                    var html = "";
                    //1达人，2一星董事，3二星董事，4三星董事
                    if (value == "1") {
                        html = "达人";
                    }
                    if (value == "2") {
                        html = "一星董事";
                    }
                    if (value == "3") {
                        html = "二星董事";
                    }
                    if (value == "4") {
                        html = "三星董事";
                    }
                    return html;
                },
            }
        },
    };
    return Controller;
});
